const Data=require('yg-Data');
const Main=require('yg-Main');
cc.Class({
    extends: cc.Component,

    properties: {
        _index:4,
        mapName:cc.Label,
        mapNode:cc.Node,
        mapContainer:cc.TiledMap
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this._index=4;
        this.loadMap();
    },
    loadMap(){
        console.log(this._index);
        let mapData=Data.maps[this._index];
        this.mapName.string=`${mapData.id}、${mapData.name}`;
        cc.resources.load(mapData.url, (err, map) => {
            //this.mapNode.destroyAllChildren();
            this.mapContainer.tmxAsset=null;
            this.mapContainer.tmxAsset=map;
            let mapSize=this.mapContainer.getMapSize();
            let scale=800/(mapSize.width*60);
            this.mapNode.scaleX=scale;
            this.mapNode.scaleY=scale;
        });
    },
    nextTap(){
        this._index++;
        if(this._index===Data.maps.length) this._index=0;
        this.loadMap();
    },
    preTap(){
        this._index--;
        if(this._index<0) this._index=Data.maps.length-1;
        this.loadMap();
    },
    closeTap(){
        this.node.destroy();
    },
    createTap(){
        // let GameServerManager=wx.getGameServerManager();
        // let mapData=Data.maps[this._index];
        // let roomExtInfo={
        //     map:mapData.id
        // }
        // GameServerManager.createRoom({
        //     maxMemberNum:mapData.maxMember,
        //     needUserInfo:true,
        //     roomExtInfo:JSON.stringify(roomExtInfo),
        //     success:(res)=>{
        //         //开始跳转房间页面
        //         Object.assign(Data.room,res.data);
                Main.roomLoadding();
        //     },
        //     fail:(res)=>{
        //         console.log(2,res)
        //     }
        // })
    }
    // update (dt) {},
});
